home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 002 / xrf / xrf0.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  7KB  |  250 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                X R F                    *
  4.  *                                    *
  5.  ************************************************************************
  6.  *                                    *
  7.  *    XRF is a cross reference utility for C source programs.        *
  8.  *    This version, written by Bob Denny of Creative Systems        *
  9.  *    design, was extracted from a DECUS C distribution kit in    *
  10.  *    April 1983 and modified to run on the Callan Data Systems    *
  11.  *    Unistar 200.                            *
  12.  *                                    *
  13.  *                    Fred Fish            *
  14.  *                    Engineering Software Tools    *
  15.  *                    Tempe, Ariz 85281        *
  16.  *                    (602) 966-8871            *
  17.  *                                    *
  18.  ************************************************************************
  19.  */
  20.  
  21. /*
  22.  *              ***************
  23.  *              * X R F 0 . C *
  24.  *              ***************
  25.  *
  26.  * This is the mainline program for the C cross referencer and lister.
  27.  * It handles the following tasks:
  28.  *
  29.  *      - Scans the command line
  30.  *      - Opens the appropriate files
  31.  *      - Calls some initialization functions
  32.  *      - Invokes line by line processing
  33.  *      - Prints the cross-reference index
  34.  *      - Finishes up processing as appropriate
  35.  *
  36.  *
  37.  * Usage:
  38.  *
  39.  *    xrf [-dn] [-o out_file] in_files
  40.  *
  41.  *    Flags:
  42.  *
  43.  *        -d    Enable debugging outputs.
  44.  *
  45.  *        -n    Narrow (80 column) output, normal is 132 column.
  46.  *
  47.  *        -o file    Write output to the indicated file.  If -o is not
  48.  *            specified, output will be to the first in_file
  49.  *            with the filetype set to ".x"
  50.  *
  51.  * Written By:
  52.  *              Bob Denny
  53.  *              Creative System Design Co.
  54.  *              3452 E. Foothill Blvd. << Suite 601 >>
  55.  *              Pasadena, Ca.  91107
  56.  *              (213) 355-6836
  57.  *
  58.  */
  59.  
  60. #include <stdio.h>
  61. #include "xrf.h"
  62.  
  63. int pageno;            /* Current listing page no. */
  64.  
  65. /************************************************************************
  66.  *                                    *
  67.  *                M A I N                    *
  68.  *                                    *
  69.  ************************************************************************
  70.  *                                    *
  71.  *  Begin Main                                *
  72.  *    Initialize debug flag to FALSE.                    *
  73.  *    Initialize list file argument pointer to NULL.            *
  74.  *    For each argument in the command line                *
  75.  *        Initialize argument character scan pointer to first char.    *
  76.  *        If this command line argument is a switch string then    *
  77.  *        While there is a switch character to process        *
  78.  *            Switch on the specific character            *
  79.  *            Case 'Outfile specified':                *
  80.  *            Erase command line argument containing switch    *
  81.  *            If there is no argument following it then    *
  82.  *                Abort with a usage message.            *
  83.  *            Else                        *
  84.  *                Save pointer to the argument.        *
  85.  *                Erase the output file name from args.    *
  86.  *                Go get the next argument.            *
  87.  *            Endif                        *
  88.  *            Case 'Narrow output':                *
  89.  *            Set references per output line.            *
  90.  *            Break                        *
  91.  *            Default:                        *
  92.  *            Abort with usage message.            *
  93.  *            End switch                        *
  94.  *        End while                        *
  95.  *        Erase the switch argument.                *
  96.  *        End if                            *
  97.  *    End for                                *
  98.  *    Set the "no output file open yet" flag.                *
  99.  *    For each command argument which was specified            *
  100.  *        If the command argument was erased then            *
  101.  *        Skip this argument and go to next.            *
  102.  *        Else                            *
  103.  *        Save the input file name pointer.            *
  104.  *        Initialize the input file.                *
  105.  *        If there is no output file open yet then        *
  106.  *            Initialize the output file.                *
  107.  *            Reset the "no output file open yet" flag.        *
  108.  *        End if                            *
  109.  *        Initialize the page number.                *
  110.  *        Initialize the line number.                *
  111.  *        Clear out any storage.                    *
  112.  *        Set current tree to NULL.                *
  113.  *        Start first output page.                *
  114.  *        While there is a line of source to process        *
  115.  *            Increment the line number.                *
  116.  *            Set line scan pointer to first character.        *
  117.  *            While there is an identifier found in line        *
  118.  *                Process the identifier.                *
  119.  *            End while                        *
  120.  *            List the current line                *
  121.  *        End while                        *
  122.  *        Start index on a new output page.            *
  123.  *            Print the index.                    *
  124.  *        End if                            *
  125.  *    End for                                *
  126.  *    If no file was output then                    *
  127.  *        Abort with usage message.                    *
  128.  *    End if                                *
  129.  *  End Main                                *
  130.  *                                    *
  131.  ************************************************************************
  132.  */
  133.  
  134. main (argc,argv)
  135. int argc;
  136. char *argv[];
  137. {
  138.     register int i;        /* Arg count */
  139.     register int c;        /* Switch character code */
  140.     register char *p;        /* Fast arg pointer */
  141.     char tolower();        /* Convert a character to lowercase */
  142.     int nofiles;        /* Flag "got a file" */
  143.     struct idt *search();
  144.  
  145.     debug = FALSE;
  146.     lst_arg = NULL;
  147.     for( i=1; i<argc; ++i ) {
  148.         p = argv[i];
  149.         if( *p++ == '-' ) {
  150.             while( c = *p++ ) {
  151.                 switch(tolower(c)) {
  152.         case 'd':
  153.             debug = TRUE;
  154.              break;    
  155.             case 'n':
  156.             rperline = (80 - 16)/RSIZE;
  157.             break;
  158.             case 'o':
  159.             argv[i] = 0;
  160.             if (++i >= argc) {
  161.             useage();
  162.             } else {
  163.             lst_arg = argv[i];
  164.                 argv[i] = 0;
  165.                 goto nextarg;
  166.             }
  167.                 default :
  168.                     useage();
  169.                 }
  170.         }
  171.         argv[i] = 0;
  172.     }
  173. nextarg:;
  174.     } 
  175.     nofiles = 1;
  176.     for( i = 1; i < argc; i++) {
  177.         if (argv[i] == 0) {
  178.         continue;
  179.     } else {
  180.         src_arg = argv[i];
  181.         if (debug) {printf("xrf: processing %s\n",src_arg);}
  182.         initinfile();
  183.             if (nofiles) {
  184.              initoutfile();
  185.                 nofiles = 0;
  186.         }
  187.             pageno = 0;
  188.         lineno = 0;
  189.         myfree();
  190.             root = NULL;
  191.             newpage();
  192.             while(fgets(scanbf, LWIDTH, src) != NULL) {
  193.                 ++lineno;
  194.                 scanp = scanbf;
  195.         if (debug) {printf("xrf: %s\n",scanbf);}
  196.                 while(getid()) {
  197.                     root = search(idbuf, root);
  198.         }
  199.                 lstline();                
  200.             }
  201.             newpage(); 
  202.             prtree(root);
  203.         if (debug) {printf("xrf: processing %s done\n",src_arg);}
  204.         }
  205.     }
  206.     if (nofiles) {
  207.         useage();
  208.     }
  209.  
  210. /*
  211.  *
  212.  * Listing control routines. Newpage also used by prtree.
  213.  *
  214.  */
  215.  
  216. newpage()
  217. {
  218.     ++pageno; 
  219.     linpg = 0;
  220.     fprintf(lst,"%s%d\n\n", pghead, pageno);
  221. }
  222.  
  223. lstline() 
  224. {
  225.     if(++linpg > MAXLIN) {
  226.         newpage();
  227.     }
  228.     fprintf(lst, "%4d:\t%s", lineno, scanbf);
  229. }
  230.  
  231. char tolower(ch)    /* FNF 26-Apr-83 Quick and dirty "tolower" */
  232. char ch;
  233. {
  234.     if ('A' <= ch && ch <= 'Z') {
  235.     return (ch + 040);
  236.     } else {
  237.     return (ch);
  238.     }
  239. }
  240.  
  241. char *cpystr(out,in)
  242. char *out;
  243. char *in;
  244. {
  245.     while ((*out++ = *in++) != NULL) {;}
  246.     return(--out);
  247. }
  248.  
  249.